package com.atshiyou.web;

import com.atshiyou.service.impl.StudentDaoServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(value = "/delstudent")
public class DeleteStuServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //1、获取参数
        String stuid2 = req.getParameter("stuid");
        int stuid = Integer.parseInt(stuid2);
        //2、调取service方法
        StudentDaoServiceImpl studentDaoService = new StudentDaoServiceImpl();
        boolean b = studentDaoService.deleteStudent(stuid);
        //跳转页面
        resp.setContentType("text/html;charset=utf-8");
        if(b){
            PrintWriter writer = resp.getWriter();
            writer.write("<script>alert('删除学生信息成功!');location.href='./index.jsp'</script>");
        }else{
            PrintWriter writer = resp.getWriter();
            writer.write("<script>alert('删除学生信息失败!');location.href='./index.jsp'</script>");
        }
    }
}
